<template>
  <div>
    <el-dialog
      :title="this.$t('common.Add')"
      :visible.sync="Visible"
      width="500px"
      :close-on-click-modal="false"
      @close="cancel"
    >
      <div class="dialogBox">
        <div class="dialogBoxItem">
          <div style="width:100%" class="dialogBoxItemRow">
            <div class="title">
              <div class="RequiredRowTip">*</div>
              {{$t('CustomerPriceTagLang.tag_name')}}:
            </div>
            <div class="contant">
              <el-input
                ref="name"
                @blur="handleBlur('name',$event)"
                @focus="handleFocus($event)"
                :placeholder="$t('common.input_plactholder')"
                v-model="data.name"
              ></el-input>
            </div>
          </div>
        </div>
        <div class="dialogBoxItem">
          <div style="width:100%" class="dialogBoxItemRow">
            <div class="title">
              <div class="RequiredRowTip">*</div>
              {{$t('CustomerPriceTagLang.label_priority')}}:
            </div>
            <div class="contant">
              <el-input-number
                controls-position="right"
                size="small" 
                ref="sort" 
                @blur="handleBlur('sort', $event)" 
                @focus="handleFocus($event)" 
                :min="0" 
                :precision="0"
                v-model="data.sort">
              </el-input-number>
            </div>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button  type="primary" @click="confirm" size="small">{{$t('common.confirm')}}</el-button
        >
        <el-button @click="cancel" size="small">{{$t('common.cancel')}}</el-button>
      </span>
      
    </el-dialog>
  </div>
</template>

<script>
export default {
  components: {
  },
  props: {
    // 接收绑定参数
    
  },
  data() {
    return {
      Visible: false,
      data: {
        name:"",
        sort:'',
      },
      confirmTrue:true,//确定按钮保护
    };
  },
  created() {
   
  },
  mounted() {},
  watch: {},
  methods: {
    init(data) {
      this.Visible = true;
    },
    // 提交
    confirm() {
      //是否有空值必选项标识
      let type = true;
      //输入框判断是否有值
      if(!this.data.name){
        this.$refs.name.$el.childNodes[1].style.border='1px solid red'
        type=false
      }
      if(!this.data.sort){
        this.$refs.sort.$el.childNodes[2].childNodes[1].style.border='1px solid red'
        type=false
      }
      if (type && this.confirmTrue) {
        this.confirmTrue=false
        window.setTimeout(()=>{
          this.confirmTrue=true
        },1000);
        let params = new FormData();
        params.append("name", this.data.name);
        params.append("sort", this.data.sort);
        this.$postForm("addMemberTag", params).then((res) => {
          this.confirmTrue = true;
          if(res.success){
            this.$message.success(res.msg);
            this.$emit("success");
            this.cancel()
          }
        });
      }
    },
    //取消
    cancel() {
      this.data = {
        name:"",
        sort:"",
      };
      this.Visible = false;
      
      let dom = document.getElementsByClassName("el-input__inner");
      for (let i = 0; i < dom.length; i++) {
         dom[i].style.border = "1px solid #E0E3E9";
      }
    },
    //输入框、下拉框失去焦点边框变色
    handleBlur(name, event) {
      if (!this.data[name]&&this.data[name]!==0) {
          event.target.style.border = "1px solid red";
        }
    },
    //输入框、下拉框获取焦点边框变色
    handleFocus(event) {
      event.target.style.border = "1px solid #E0E3E9";
    },
  },
};
</script>

<style scoped lang="less" >
  .dialogBox .dialogBoxItem .dialogBoxItemRow{
    width: 23%;
  }
  /deep/ .el-dialog__wrapper{
    .el-dialog{
      min-width: 500px;
    }
  }
  .iphoneClass{
    position: relative;
    /deep/.el-input__inner{
      padding-left: 105px;
    }
    /deep/.el-input-group__prepend{
      position: absolute;
      width: 100px;
      top: 1px;
      left: 2px;
      border: 0;
      height: 32px;
      padding: 0;
    }
  }
  .accountTitle{
    display: flex;
    align-items: center;
    justify-content: center;
    /deep/.el-popover__reference{
      height: 34px;
    }
    img{
      width: 25px;
      height: 25px;
      border-radius: 50%;
    }
  }
</style>